﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DLV.Utilities;
using DLV.Library.Utilities;

namespace DLV.Data.Entities
{
    public class InsuranceController
    {
        public int InsertInsurance(InsuranceInfo info)
        {
            return SQL.InsertInsurance(info.PartnerId, info.InsuranceName, info.InsuranceLevel, info.InsuranceBegin, info.SortDescription, info.DetailDescription, info.CreatedBy, info.CreatedDate, info.UpdatedBy, info.UpdatedDate, info.Status);
        }
        public void UpdateInsurance(InsuranceInfo info)
        {
            SQL.UpdateInsurance(info.InsuranceId, info.PartnerId, info.InsuranceName, info.InsuranceLevel, info.InsuranceBegin, info.SortDescription, info.DetailDescription, info.CreatedBy, info.CreatedDate, info.UpdatedBy, info.UpdatedDate, info.Status);
        }
        public void DeleteInsurance(InsuranceInfo info)
        {
            DeleteInsurance(info.InsuranceId);
        }
        public void DeleteInsurance(int insuranceId)
        {
            SQL.DeleteInsurance(insuranceId);
        }
        public InsuranceInfo GetInsurance(int insuranceId)
        {
            return CBO.FillObject<InsuranceInfo>(SQL.GetInsurance(insuranceId));
        }
        public List<InsuranceInfo> ListInsurance()
        {
            return CBO.FillCollection<InsuranceInfo>(SQL.ListInsurance());
        }
        public List<InsuranceInfo> ListInsuranceByStatus(int status)
        {
            return ListInsurance().Where(p => p.Status == (int)Globals.DocumentStatus.Use).ToList();
        }
        public List<InsuranceInfo> ListInsuranceByPartner(int partnerId)
        {
            return ListInsurance().Where(p => p.PartnerId == partnerId).ToList();
        }
        public DataTable SelectInsurance()
        {
            return CBO.ConvertToDataTable(ListInsurance(), typeof(InsuranceInfo));
        }

        public Dictionary<object, object> ListInsuranceLookup()
        {
            var users = ListInsuranceByStatus((int)Globals.DocumentStatus.Use).OrderBy(p=>p.InsuranceName);
            var dicusers = new Dictionary<object, object>();
           
            foreach (InsuranceInfo info in users)
            {
                
                dicusers.Add(info.InsuranceId, info.InsuranceName);                
            }
            return dicusers;
        }
    }
}
